package com.cc;

import domain.Rectangle;

import java.util.Random;

/**
 * @author cpp
 * @version 1.0
 * @date 2025/3/18 17:08
 * @description
 */

public class OOPDemo07 {
    public static void main(String[] args) {
        Rectangle[] rectangle = new Rectangle[5];
        //创造5个矩形对象放进数组
        for (int i = 0; i < rectangle.length; i++) {
            double length = new Random().nextDouble() * 9 + 1;
            double kuan = new Random().nextDouble() * 9 + 1;
            rectangle[i] = new Rectangle(length, kuan);
        }
        for (int i = 0; i < rectangle.length; i++) {
            System.out.println(rectangle[i].getInfo());
        }
        for (int i = 0; i < rectangle.length; i++) {
            for (int j = 0; j < rectangle.length - 1; j++) {
                if (rectangle[j].getArea() > rectangle[j + 1].getArea()) {
                    Rectangle temp = rectangle[j];
                    rectangle[j] = rectangle[j + 1];
                    rectangle[j + 1] = temp;
                }

            }

        }
        System.out.println("================================");
        for (int i = 0; i < rectangle.length; i++) {
            System.out.println(rectangle[i].getInfo());
        }

    }
}
